#include <lkhos/arch/interrupts.h>
#include <lkhos/arch/idt.h>
#include <stdint.h>

#define IDT_ENTRY 32

uint64_t _idt[IDT_ENTRY];
uint16_t _idt_limit = sizeof(_idt) - 1;

// isr: interrupts service routine
void set_idt_entry(uint32_t vector, uint16_t seg_selector, uint32_t dpl, void (*isr)()) {
    uintptr_t offset = (uintptr_t)isr;
    _idt[vector] = (offset & 0xffff0000) | IDT_ATTR(dpl);
    _idt[vector] <<= 32;
    _idt[vector] |= (seg_selector << 16) | (offset & 0x0000ffff);
}

void _idt_init() {
    set_idt_entry(VEC_DIVIDE_ERROR, 0x8, 0, isr0);
}